/*
 * Copyright (c) 2018. paascloud.net All Rights Reserved.
 * 项目名称：paascloud快速搭建企业级分布式微服务平台
 * 类名称：UacGroupMainController.java
 * 创建人：刘兆明
 * 联系方式：paascloud.net@gmail.com
 * 开源地址: https://github.com/paascloud
 * 博客地址: http://blog.paascloud.net
 * 项目官网: http://paascloud.net
 */

package com.csun.cmny.provider.controller.admin;


import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.core.annotation.ValidateAnnotation;
import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.domain.*;
import com.csun.cmny.provider.model.dto.dept.EmpQueryDto;
import com.csun.cmny.provider.model.dto.group.*;
import com.csun.cmny.provider.model.dto.properManagement.GroupByGroupNameDto;
import com.csun.cmny.provider.model.dto.properManagement.LoginNameByGroupIdDto;
import com.csun.cmny.provider.model.dto.user.IdStatusDto;
import com.csun.cmny.provider.model.vo.*;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.*;
import com.csun.cmny.provider.validator.UacGroupAddValidator;
import com.csun.cmny.util.RedisKeyUtil;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 组织管理主页面
 *
 * @author paascloud.net @gmail.com
 */
@RestController
@RequestMapping(value = "/group", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "Web - UacGroupMainController", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class UacGroupMainController extends BaseController {

	@Resource
	private UacGroupService uacGroupService;
	@Resource
	private CmnyMessageSource cmnyMessageSource;
	@Resource
	private UacGroupRoleMenuService uacGroupRoleMenuService;
	@Resource
	private UacGroupRoleActionService uacGroupRoleActionService;
	@Resource
	private UacGroupRoleService uacGroupRoleService;
	@Resource
    private UacDeptService uacDeptService;
	@Resource
    private UacEmpService uacEmpService;
	@Resource
	private UacMenuService uacMenuService;
	@Resource
	private RedisTemplate<String,Object> redisTemplate;

	/**
	 * 查询机构列表
	 *
	 * @return
	 */
	@PostMapping(value = "/queryListWithPage")
	public Wrapper queryListWithPage(@RequestBody GroupQueryDto groupQueryDto) {

		PageInfo pageInfo = uacGroupService.queryUacGroupListWithPage(groupQueryDto);

		//return WrapMapper.ok(pageInfo);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), pageInfo);
	}

	/**
	 * 根据id删除组织
	 *
	 * @param id the id
	 *
	 * @return the wrapper
	 */
	@PostMapping(value = "/deleteById/{id}")
	//@LogAnnotation
	@ApiOperation(httpMethod = "POST", value = "根据id删除组织")
	public Wrapper deleteGroupById(@ApiParam(name = "id", value = "组织id") @PathVariable Long id) {
		logger.info(" 根据id删除组织 id={}", id);
		int result = uacGroupService.deleteUacGroupById(id);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 根据id修改组织状态
	 *
	 * @param idStatusDto the id status dto
	 *
	 * @return the wrapper
	 */
	@PostMapping(value = "/modifyStatus")
	//@LogAnnotation
	@ApiOperation(httpMethod = "POST", value = "根据id修改组织状态")
	public Wrapper modifyGroupStatus(@ApiParam(name = "modifyGroupStatus", value = "修改状态") @RequestBody IdStatusDto idStatusDto) {
		logger.info("根据id修改组织状态 idStatusDto={}", idStatusDto);
		UacGroup uacGroup = new UacGroup();
		uacGroup.setId(idStatusDto.getId());
		LoginAuthDto loginAuthDto = super.getLoginAuthDto();
		Integer status = idStatusDto.getStatus();
		uacGroup.setStatus(status);
		int result = uacGroupService.updateUacGroupStatusById(idStatusDto, loginAuthDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, "操作失败");
		} else {
			return WrapMapper.wrap(Wrapper.SUCCESS_CODE, "操作成功");
		}
	}


	/**
	 * 获取主页面数据
	 *
	 * @return the wrapper
	 */
	@PostMapping(value = "/getTree")
	@ApiOperation(httpMethod = "POST", value = "获取菜单树")
	public Wrapper<List<MenuVo>> getTree() {
		Long userId = super.getLoginAuthDto().getUserId();
		List<MenuVo> tree = uacGroupService.getGroupTreeListByUserId(userId);
		//return WrapMapper.ok(tree);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), tree);
	}

	/**
	 * 添加组织
	 *
	 * @param group the group
	 *
	 * @return the wrapper
	 */
	@ValidateAnnotation
	@PostMapping(value = "/save")
	//@LogAnnotation
	@ApiOperation(httpMethod = "POST", value = "添加组织信息")
	public Wrapper addGroup(@ApiParam(name = "group", value = "组织信息")
								 @Validated(UacGroupAddValidator.class)
								 @RequestBody UacGroup group, BindingResult br) {
		LoginAuthDto loginAuthDto = super.getLoginAuthDto();
		Integer result = uacGroupService.addUacGroup(group, loginAuthDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 修改组织
	 *
	 * @param group the group
	 *
	 * @return the wrapper
	 */
	@ValidateAnnotation
	@PostMapping(value = "/edit")
	//@LogAnnotation
	@ApiOperation(httpMethod = "POST", value = "修改组织信息")
	public Wrapper editGroup(@ApiParam(name = "group", value = "组织信息")
							 @RequestBody UacGroup group) {

		LoginAuthDto loginAuthDto = super.getLoginAuthDto();
		Integer result = uacGroupService.updateUacGroup(group, loginAuthDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 获取编辑页面数据
	 *
	 * @param id the id
	 *
	 * @return the edit group page info
	 */
	@PostMapping(value = "/queryById/{id}")
	@ApiOperation(httpMethod = "POST", value = "获取编辑页面数据")
	public Wrapper<UacGroup> getEditGroupPageInfo(@ApiParam(name = "id", value = "组织id") @PathVariable Long id) {
		UacGroup uacGroup = uacGroupService.getById(id);
		//return WrapMapper.ok(uacGroup);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), uacGroup);
	}

	/**
	 * 初始化机构组织架构
	 *
	 * @param initDeptEmpDto	the init dept emp dto
	 *
	 * @return	the wrapper.
	 */
	@ValidateAnnotation
	@PostMapping(value = "/initDeptEmp")
	public Wrapper initDeptEmp(@Validated @RequestBody InitDeptEmpDto initDeptEmpDto) {

		Integer result = uacGroupService.initDeptEmp(initDeptEmpDto, getLoginAuthDto());
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

    /**
     * 查询部门全部信息
     *
     * @param groupId   the group id
     *
     * @return  the wrapper.
     */
    @PostMapping("/getDeptTreeByGroupId/{groupId}")
    public Wrapper<List<DeptVo>> getDeptTreeByGroupId(@PathVariable Long groupId) {

        List<DeptVo> deptVoList = uacDeptService.getDeptVoAll(groupId);

        //return WrapMapper.ok(deptVoList);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), deptVoList);
    }

    /**
     * 查询部门员工信息列表 - 分页
     *
     * @param empQueryDto   the emp query dto
     *
     * @return  the wrapper.
     */
    @RequestMapping(value = "/queryEmpListWithPage", method = RequestMethod.POST)
    public Wrapper queryEmpListWithPage(@RequestBody EmpQueryDto empQueryDto) {

        Preconditions.checkArgument(empQueryDto.getGroupId() != null,
                cmnyMessageSource.getMessage("group.id.null", null));

        Preconditions.checkArgument(empQueryDto.getDeptId() != null,
                cmnyMessageSource.getMessage("dept.id.null", null));

        PageInfo pageInfo = uacEmpService.queryEmpListWithPage(empQueryDto);

        //return WrapMapper.ok(pageInfo);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), pageInfo);
    }

	/**
	 * 初始化机构角色
	 *
	 * @param initRoleDto	the init role dto
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/initRole")
	public Wrapper initRole(@RequestBody InitRoleDto initRoleDto) {

		Integer result = uacGroupService.initRole(initRoleDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 查询机构角色列表
	 *
	 * @param groupRoleQueryDto	the group role query dto
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/queryRoleList")
	public Wrapper queryRoleList(@RequestBody GroupRoleQueryDto groupRoleQueryDto) {

		List<RoleVo> roleVoList = uacGroupService.queryRoleList(groupRoleQueryDto);

		//return WrapMapper.ok(roleVoList);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), roleVoList);
	}

	/**
	 * 分配机构角色
	 *
	 * @param initRoleDto	the init role dto
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/bindRole")
	public Wrapper bindRole(@RequestBody InitRoleDto initRoleDto) {

		Integer result = uacGroupService.bindRole(initRoleDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 机构添加角色
	 *
	 * @param groupRoleDto	the group role dto
	 *
	 * @return	the wrapper.
	 */
	@ValidateAnnotation
	@PostMapping(value = "/assignRole")
	public Wrapper assignRole(@Validated @RequestBody GroupRoleDto groupRoleDto, BindingResult br) {

		Integer result = uacGroupRoleService.assignGroupRole(groupRoleDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	@ValidateAnnotation
	@PostMapping(value = "/deleteRole")
	public Wrapper deleteRole(@Validated @RequestBody GroupRoleDto groupRoleDto, BindingResult br) {

		Integer result = uacGroupRoleService.deleteGroupRole(groupRoleDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 根据机构Id查询角色列表
	 *
	 * @param groupId	the group id
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/queryRoleListByGroupId/{groupId}")
	public Wrapper queryRoleListByGroupId(@PathVariable Long groupId) {

		List<UacRole> uacRoleList = uacGroupRoleService.queryRoleListByGroupId(groupId);

		//return WrapMapper.ok(uacRoleList);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), uacRoleList);
	}

	/**
	 * 移除单个角色用户
	 *
	 * @param uacRoleUser
	 * @return
	 */
//	@PostMapping(value = "/singleDeleteRoleUser")
//	public Wrapper singleDeleteRoleUser(@RequestBody UacRoleUser uacRoleUser) {
//
//		Integer result = uacGroupService.delete(uacRoleUser);
//		if (result < 1) {
//			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
//					.getMessage("operation.failed", null));
//		}
//
//		return WrapMapper.ok(result);
//	}

	/**
	 * 批量移除角色用户
	 *
	 * @param roleBindUserReqDto	the role bind user req dto
	 *
	 * @return	the int.
	 */
//	@PostMapping(value = "/batchDeleteUser")
//	public Wrapper batchDeleteRoleUser(@RequestBody RoleBindUserReqDto roleBindUserReqDto) {
//
//		Integer result = uacGroupService.batchDeleteRoleUser(roleBindUserReqDto);
//		if (result < 1) {
//			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
//					.getMessage("operation.failed", null));
//		}
//
//		return WrapMapper.ok(result);
//	}

	/**
	 * 分配机构角色-用户
	 *
	 * @param groupRoleAssignUserDto	the group role assign user dto
	 *
	 * @return	the wrapper.
	 */
//	@PostMapping(value = "/assignRoleUser")
//	public Wrapper assignRoleUser(@RequestBody GroupRoleAssignUserDto groupRoleAssignUserDto) {
//
//		Integer result = uacGroupService.assignRoleUser(groupRoleAssignUserDto);
//		if (result < 1) {
//			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
//					.getMessage("operation.failed", null));
//		}
//
//		return WrapMapper.ok(result);
//	}

	/**
	 * 查询角色用户列表
	 *
	 * @param groupUserQueryDto	the group user query dto
	 *
	 * @return	the wrapper
	 */
//	@PostMapping(value = "/queryRoleUserListWithPage")
//	public Wrapper queryRoleUserListWithPage(@RequestBody GroupUserQueryDto groupUserQueryDto) {
//
//		PageHelper.startPage(groupUserQueryDto.getPageNum(), groupUserQueryDto.getPageSize());
//
//		List<UacUser> uacUserList = uacGroupService.queryRoleUserList(groupUserQueryDto);
//
//		return WrapMapper.ok(new PageInfo<>(uacUserList));
//	}

	/**
	 * 移除单个角色菜单
	 *
	 * @param uacGroupRoleMenu	the uac group role menu
	 *
	 * @return	wrapper
	 */
	@PostMapping(value = "/singleDeleteRoleMenu")
	public Wrapper singleDeleteMenu(@RequestBody UacGroupRoleMenu uacGroupRoleMenu) {

        Preconditions.checkArgument(uacGroupRoleMenu.getGroupId() != null,
                cmnyMessageSource.getMessage("group.id.null", null));

        Preconditions.checkArgument(uacGroupRoleMenu.getMenuId() != null,
                cmnyMessageSource.getMessage("menu.id.null", null));

        Preconditions.checkArgument(uacGroupRoleMenu.getRoleId() != null,
                cmnyMessageSource.getMessage("role.id.null", null));

//		GroupRoleDto groupRoleDto = new GroupRoleDto();
//		groupRoleDto.setRoleId(uacGroupRoleMenu.getRoleId());
//		groupRoleDto.setGroupId(uacGroupRoleMenu.getGroupId());
//		List<Long> roleMenuIdList = uacGroupRoleMenuService.getCheckedMenuList(groupRoleDto);
//		List<Long> menuIdList;
//		if (PublicUtil.isEmpty(roleMenuIdList)) {
//			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
//					.getMessage("operation.failed", null));
//		} else {
//			menuIdList = uacMenuService.queryMenuAndSubMenuIdsInMenuList(uacGroupRoleMenu.getMenuId(), roleMenuIdList);
//		}

		List<Long> menuIdList = uacMenuService.queryMenuAndSubMenuIds(uacGroupRoleMenu.getMenuId());

		GroupRoleMenuListDto groupRoleMenuListDto = new GroupRoleMenuListDto();
		groupRoleMenuListDto.setGroupId(uacGroupRoleMenu.getGroupId());
		groupRoleMenuListDto.setRoleId(uacGroupRoleMenu.getRoleId());
		groupRoleMenuListDto.setMenuIdList(menuIdList);
		// Integer result = uacGroupRoleMenuService.delete(uacGroupRoleMenu);
		Integer result = uacGroupRoleMenuService.batchDeleteRoleMenu(groupRoleMenuListDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 批量移除机构角色菜单
	 *
	 * @param groupRoleMenuListDto	the group role menu list dto
	 *
	 * @return	the wrapper.
	 */
	@ValidateAnnotation
	@PostMapping(value = "/batchDeleteRoleMenu")
	public Wrapper batchDeleteRoleMenu(@Validated @RequestBody GroupRoleMenuListDto groupRoleMenuListDto) {

		// 需要删除该菜单及子菜单
		List<Long> menuIdList = Lists.newArrayList();
		for (Long menuId : groupRoleMenuListDto.getMenuIdList()) {
			List<Long> list = uacMenuService.queryMenuAndSubMenuIds(menuId);
			menuIdList.addAll(list);
		}

		groupRoleMenuListDto.setMenuIdList(menuIdList);

		Integer result = uacGroupRoleMenuService.batchDeleteRoleMenu(groupRoleMenuListDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 分配机构角色菜单
	 *
	 * @param groupRoleAssignMenuDto	the group role assign menu dto
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/assignRoleMenu")
	public Wrapper assignRoleMenu(@RequestBody GroupRoleAssignMenuDto groupRoleAssignMenuDto) {

		Integer result = uacGroupRoleMenuService.assignRoleMenu(groupRoleAssignMenuDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 获取机构角色菜单树.
	 *
	 * @param groupRoleDto	the group role
	 *
	 * @return
	 */
	@ValidateAnnotation
	@PostMapping(value = "/getRoleMenuTree")
	public Wrapper<BindAuthVo> getGroupRoleMenuTree(@Validated @RequestBody GroupRoleDto groupRoleDto, BindingResult br) {

		BindAuthVo bindAuthVo = uacGroupRoleMenuService.getGroupRoleMenuTree(groupRoleDto);

		//return WrapMapper.ok(bindAuthVo);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), bindAuthVo);
	}

	/**
	 * 查询角色菜单列表-分页查询
	 *
	 * @param groupMenuQueryDto	the group menu query dto
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/queryRoleMenuListWithPage")
	public Wrapper queryRoleMenuListWithPage(@RequestBody GroupMenuQueryDto groupMenuQueryDto) {

		PageInfo pageInfo = uacGroupRoleMenuService.queryRoleMenuListWithPage(groupMenuQueryDto);

		//return WrapMapper.ok(pageInfo);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), pageInfo);
	}

	/**
	 * 移除单个机构角色功能
	 *
	 * @param uacGroupRoleAction	the uac group role action
	 *
	 * @return	wrapper
	 */
	@PostMapping(value = "/singleDeleteRoleAction")
	public Wrapper singleDeleteAction(@RequestBody UacGroupRoleAction uacGroupRoleAction) {

        Preconditions.checkArgument(uacGroupRoleAction.getGroupId() != null,
                cmnyMessageSource.getMessage("group.id.null", null));

        Preconditions.checkArgument(uacGroupRoleAction.getActionId() != null,
                cmnyMessageSource.getMessage("action.id.null", null));

        Preconditions.checkArgument(uacGroupRoleAction.getRoleId() != null,
                cmnyMessageSource.getMessage("role.id.null", null));

		Integer result = uacGroupRoleActionService.delete(uacGroupRoleAction);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 批量移除机构角色功能
	 *
	 * @param groupRoleActionListDto	the group role action list dto
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/batchDeleteRoleAction")
	public Wrapper batchDeleteRoleAction(@RequestBody GroupRoleActionListDto groupRoleActionListDto) {

		Integer result = uacGroupRoleActionService.batchDeleteRoleAction(groupRoleActionListDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 分配机构角色功能
	 *
	 * @param groupRoleAssignActionDto	the group role assign action dto
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/assignRoleAction")
	public Wrapper assignRoleAction(@RequestBody GroupRoleAssignActionDto groupRoleAssignActionDto) {

		Integer result = uacGroupRoleActionService.assignRoleAction(groupRoleAssignActionDto);
		if (result < 1) {
			return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
					.getMessage("operation.failed", null));
		}

		//return WrapMapper.ok(result);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), result);
	}

	/**
	 * 获取权限树
	 *
	 * @param groupRoleDto	the group role dto
	 *
	 * @return the auth tree by role id
	 */
	@PostMapping(value = "/getRoleActionTree")
	public Wrapper<BindAuthVo> getGroupRoleActionTree(@RequestBody GroupRoleDto groupRoleDto) {

		BindAuthVo bindAuthVo = uacGroupRoleActionService.getGroupRoleActionTree(groupRoleDto);

		//return WrapMapper.ok(bindAuthVo);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), bindAuthVo);
	}

	/**
	 * 获取机构角色功能列表
	 *
	 * @param groupActionQueryDto	the group action query dto
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/queryRoleActionListWithPage")
	public Wrapper queryRoleActionListWithPage(@RequestBody GroupActionQueryDto groupActionQueryDto) {

		PageInfo pageInfo = uacGroupRoleActionService.queryRoleActionListWithPage(groupActionQueryDto);

		//return WrapMapper.ok(pageInfo);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), pageInfo);
	}

	/**
	 * 获取机构角色功能列表
	 *
	 * @param uacGroupRoleAction	the uac group role action
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/queryRoleAction")
	public Wrapper queryRoleAction(@RequestBody UacGroupRoleAction uacGroupRoleAction) {

		Preconditions.checkArgument(uacGroupRoleAction.getGroupId() != null,
				cmnyMessageSource.getMessage("group.id.null", null));

		Preconditions.checkArgument(uacGroupRoleAction.getActionId() != null,
				cmnyMessageSource.getMessage("action.id.null", null));

		Preconditions.checkArgument(uacGroupRoleAction.getRoleId() != null,
				cmnyMessageSource.getMessage("role.id.null", null));

		UacAction uacAction = uacGroupRoleActionService.queryRoleAction(uacGroupRoleAction);

		//return WrapMapper.ok(uacAction);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), uacAction);
	}

	/**
	 * 查询没有绑定该机构的角色Id
	 *
	 * @param groupId	the group id
	 *
	 * @return	the wrapper.
	 */
	@PostMapping(value = "/queryNotBindRoleListByGroupId/{groupId}")
	public Wrapper queryNotBindRoleListByGroupId(@PathVariable Long groupId) {

		List<UacRole> uacRoleList = uacGroupRoleService.queryNotBindRoleListByGroupId(groupId);

		//return WrapMapper.ok(uacRoleList);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), uacRoleList);
	}

	@PostMapping(value = "/selectGroups")
	@ApiOperation(httpMethod = "POST", value = "查询所有机构信息")
	public Wrapper selectGroups(GroupByGroupNameDto groupByGroupNameDto) {

		List<PropertyManagementGroupVo> list = uacGroupService.selectGroups(groupByGroupNameDto);


		//return WrapMapper.ok(pageInfo);
		return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
				.getMessage("operation.success", null), list);
	}


}
